<?php
/**********************************************
* 파일명: files.php
* 설  명: 해당스킨폴더에 첨부된 파일을 보여줍니다.
***********************************************/
if ($skinfolder == '') 
	$skinfolder = $start;
else
	$skinfolder = $start.$skinfolder;

if (!$dp = @opendir($skinfolder)) {
	TT_SkinManagerMsg(pluginLang::plts('잘못된 폴더명이거나 존재하지 않는 폴더입니다'));
	exit;
}

if ($start != $skinfolder) {
	$folders = array();
	while ($dir = @readdir($dp)) {
		if($dp2=@opendir("$skinfolder/$dir") && $dir != '.' &&  $dir != '..') {
			$folders[] = $dir;
		}
		if(!eregi("\.($exts)$",$dir) && !eregi("\.($skinfiles)$",$dir)) {
			continue;
		}
		$dirs[] = $dir;
		@closedir($dp2);
	}

	@sort($dirs);
}
?>
	<div class="skinList">
		<p class="currentFolder">
			<?php echo pluginLang::plts('현재폴더');?> : <strong><?php echo str_replace(ROOT,'', $skinfolder);?></strong>
<?php
if($start != $skinfolder){
?>
			<span>(<strong><?php echo number_format(@sizeof($dirs));?></strong> Files)</span>
<?php
}
?>
		</p>
<?php
if ($skinfolder == $start){
?>
		<ul class="navigation">
			<li><a href="<?php echo $pluginMenuURL;?>&amp;sort=name" class="btn"><?php echo pluginLang::plts('이름순');?></a></li>
			<li><a href="<?php echo $pluginMenuURL;?>&amp;sort=time" class="btn"><?php echo pluginLang::plts('생성순');?></a></li>				
		</ul>
<?php
}

if($start != $skinfolder){
require_once ROOT.'/script/detectFlash.inc';
$curdir = str_replace(ROOT,"",$skinfolder);
?>
		<ul class="folder">
			<li>
				<script language="JavaScript" type="text/javascript">
					//<![CDATA[
						var requiredMajorVersion = 8;
						var requiredMinorVersion = 0;
						var requiredRevision = 0;
						var jsVersion = 1.0;
		
						var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
						//hasRightVersion =false;
						if(hasRightVersion){
						uploaderUrl = '<a href="#void" class="btn" onclick="openPopup(\'<?php echo $blogURL."/plugin/TT_SkinManagerUpload/?dir=".TT_SkinManagerEncode($curdir,"e");?>\', 400, 300, \'_fileup\',\'\');" ><?php echo pluginLang::plts('파일업로드');?><\/a>';
						}else{
						uploaderUrl = '<a href="#void" class="btn" onclick="openPopup(\'<?php echo $blogURL."/plugin/TT_SkinManagerUpload2/?dir=".TT_SkinManagerEncode($curdir,"e");?>\', 400, 300, \'_fileup\',\'\');"><?php echo pluginLang::plts('파일업로드');?><\/a>';				
						}
						  document.write(uploaderUrl);
					//]]>
				</script>	
			</li>
			<li class="makeFolder"><input type="text" class="input-text" name="sub_dir" value="" /><a href="#void" class="btn" onclick="return js_sub_confirm();"><?php echo pluginLang::plts('폴더생성');?></a></li>
			<li><a href="#void" class="btn" onclick="delete_folder('<?php echo $curdir;?>');"><?php echo pluginLang::plts('폴더삭제');?></a></li>
		</ul>
<?php
}

if ($skinfolder == $start) {
?>
		<ul class="mySkinList2">
<?php
	$dh=@opendir($start);

	$skin_names =array();
	while($dir=@readdir($dh)){
		if ($dir == '.' || $dir== '..' || $dir == 'customize') {
			continue;
		}
		if (is_dir("$start/$dir")) {
			$ctime = filectime("$start/$dir");
			$skin_names[$dir] =  $ctime;
		}
	}

	$skin_folders = array();

	if($sort == "time"){
		$skin_names = array_sort($skin_names,"desc");	
		foreach($skin_names as $key => $val) {
			$skin_folders[] = $key;
		}	 
	} else {
	 	uksort($skin_names, "strcasecmp");
		foreach($skin_names as $key => $val) {
			$skin_folders[] = $key;
		}	
	}
	$i = 0;

	foreach($skin_folders as $dir) {
		$previewfile = $start.$dir."/preview.gif"; 
		if (!file_exists($previewfile))
			$previewfile = $pluginURL."/image/blank.gif"; 
		else
			$previewfile = $service['path']."/skin/".$dir."/preview.gif"; 
	
		echo "
			<li>
				<div class=\"skin\">
					<table style=\"height:100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
						<tr><td><a href=\"#void\" title=\"$dir\" onclick=\"js_skin_submit('".$dir."', '".$dir."/'); return false;\"><img src=\"$previewfile\" alt=\"$dir\" width=\"120\" height=\"120px\" /></a></td></tr>
					</table>
				</div>
				<div class=\"title\"><span>$dir</span></div>
				<div class=\"buttons\">
					<a class=\"btn preview\" href=\"{$blogURL}/owner/skin/preview/?skin=$dir\" onclick=\"window.open(this.href); return false;\">".pluginLang::plts('미리보기')."</a>
					<a class=\"btn confirm\" href=\"#void\" onclick=\"return js_skin_confirm('$dir');\">".pluginLang::plts('적용하기')."</a>
				</div>
			</li>";
		$i++;
	}
	@closedir($dh);
?>
		</ul>
<?php
}

if($start != $skinfolder){
?>
		<ul class="mySkinList2">
<?php
	$mfolder =str_replace($start,"",$skinfolder);
	$tmp = explode("/", $mfolder);
	$mofolder ="";
	if(count($tmp) >2){
		for($i =0;$i < count($tmp)-2;$i++){
			$mofolder .= $tmp[$i]."/";
		}
		$mfolder = $mofolder;
	}else{
		$mfolder = "";	
	}
	$imgfile = $pluginURL."/image/icon_folder.gif";

	echo "
			<li>
				<div class=\"skin\">
				<div class=\"fileButton\">&nbsp;</div>
					<table style=\"height:100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
						<tr><td><a href=\"#void\" title='".pluginLang::plts('폴더보기')."' onclick=\"js_skin_submit('".$skinname."','".$mfolder."');return false;\"><img src=\"".$pluginURL."/image/icon_folder.gif\" alt=\"".pluginLang::plts('폴더')."\" /></a></td></tr>
					</table>
				</div>
				<div class=\"title\"><span><a onfocus=\"this.blur()\" href=\"#void\" onclick=\"js_skin_submit('".$skinname."','".$mfolder."');return false;\"><strong>..</strong></a></span></div>
			</li>";
	
	$filescnt = 1;
	if(is_array($folders)){

		foreach($folders as $folder){
		$gofolder =  str_replace($start,"",$skinfolder).$folder."/";
		$gofoldername = $folder;
		$imgfile = $pluginURL."/image/icon_folder.gif";

		echo "<li>
					<div class=\"skin\">
					<div class=\"fileButton\" >&nbsp;</div>
					  <table style=\"height:100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
	                    <tr><td><a href='#void' title='".pluginLang::plts('폴더보기')."' onclick=\"js_skin_submit('".$skinname."','".$gofolder."');return false;\"><img src=\"".$pluginURL."/image/icon_folder.gif\" alt=\"".pluginLang::plts('폴더')."\" /></a></td></tr>
	                  </table>
					  <div class=\"title\"><span><a onfocus=\"this.blur()\" href='#void' onclick=\"js_skin_submit('".$skinname."','".$gofolder."');return false;\"><strong>$gofoldername</strong></a></span></div>
					</div>
					<div class=\"fileTitle\">&nbsp;</div>
				</li>";

			$filescnt++;
		}
	}
	
	for($k=0; $k<sizeof($dirs); $k++) {

	$filename = $skinfolder.$dirs[$k];

		if(eregi("\.($exts)$",$skinfolder."/".$dirs[$k])){
			$size	= @getImageSize("$skinfolder/$dirs[$k]");
			$imgfile = $service['path'].str_replace(ROOT,"",$skinfolder).$dirs[$k];
			$imgchk = "T";
		}else{
			$imgfile = $pluginURL."/image/icon_text.gif";
			$size = array(0,0);
			$imgchk = "F";
		}
		$len = @fileSize("$skinfolder/$dirs[$k]");

		$filename = str_replace(ROOT,"",$filename);

		$edit_menu =($imgchk == "F")?"<a href=\"#void\" onclick=\"edit_file('".$filename."', 'skinfile$k'); return false;\" title=\"".pluginLang::plts('수정하기')."\"><img src=\"".$pluginURL."/image/iconUpdate.gif\" border=0 alt=\"".pluginLang::plts('수정하기')."\" /></a>":"";

		if($imgchk == "F"){
			$imgfile_link =  "<a href=\"#void\" onclick=\"edit_file('".$filename."', 'skinfile$k'); return false;\" title=\"".pluginLang::plts('수정하기')."\"><img src=\"$imgfile\" name=\"img$k\" alt=\"".pluginLang::plts('수정하기')."\"  class=\"img_preview\" /></a>";
		}else{
			if (eregi("\.(swf)$",$imgfile)) $imgfile ="/image/extension/swf.gif";
			$imgfile_link = "<a href=\"#void\" onclick=\"openPopup('".$imgfile."',500,500,'_fileups','scrollbars=1,resizable=1'); return false;\" title=\"".pluginLang::plts('파일보기')."\"><img src=\"$imgfile\" id=\"img_$k\" name=\"img_$k\" class=\"img_preview\" style=\"display:none;\" alt=\"view\" /></a>";
		}	

		echo "<li>
					<div class=\"skin\" id=\"skinfile$k\">
					<div class=\"fileButton\">$edit_menu <a href=\"#void\" onclick=\"delete_file('".$filename."', 'skinfile$k'); return false;\" title='".pluginLang::plts('삭제하기')."'><img src=\"".$pluginURL."/image/iconFailure.gif\" alt=\"".pluginLang::plts('삭제하기')."\" width=\"10\" height=\"10\" /></a></div>
					  <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
	                    <tr><td id=\"cell$k\">$imgfile_link</td></tr>
	                  </table>
					  <div class=\"title\"><span><a href=\"#void\" onclick=\"copy_tag('".$hostURL. str_replace(ROOT,"",$skinfolder).$dirs[$k]."');return false;\" title=\"".pluginLang::plts('주소복사')."\">$dirs[$k]</a></span></div>
					</div>
					<div class=\"fileTitle\">{$size[0]} x {$size[1]} px. ". number_format(ceil($len /1024))." kb</div>
				</li>";
		$filescnt++;
	}
?>
		</ul>
<?php
}
?>
		<div class="clear"></div>
	</div>
	<div id="msgdiv"></div>
	<iframe src="about:blank" name="ifrm" width="0" height="0" style="display:none;"></iframe> 
